package com.liusand.user.controller;

import com.liusand.entity.dto.LocationDto;
import com.liusand.entity.vo.PageInfo;
import com.liusand.entity.vo.Result;
import com.liusand.entity.vo.UserVo;
import com.liusand.user.service.LocationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.geo.GeoResults;
import org.springframework.data.redis.connection.RedisGeoCommands;
import org.springframework.web.bind.annotation.*;

/**
 * @author :liusha
 * packageName :com.liusand.user.controller
 * fileName :LocationController
 * creationTime :2022/12/15 20:33
 */
@RestController
@RequestMapping("/user/location")
public class LocationController {

    @Autowired
    private LocationService locationService;

    @PostMapping
    public Result sendLocationInfo(@RequestBody LocationDto locationDto){
        if(locationDto.getLongitude() == null || locationDto.getLatitude() == null){
            return Result.error("发送位置信息失败");
        }
        boolean result = locationService.sendLocationInfo(locationDto);
        if(!result){
            return Result.error("发送位置信息失败");
        }
        return Result.success();
    }

    @GetMapping
    public Result getNearPeople(@RequestParam(required = false) Integer gender,
                                @RequestParam(defaultValue = "1") Integer radius,
                                @RequestParam(defaultValue = "1") Integer page,
                                @RequestParam(defaultValue = "10") Integer pageSize){
        PageInfo<UserVo> result = locationService.getNearPeople(gender, radius, page, pageSize);
        return Result.success(result);
    }

}
